/**
 * Created with IntelliJ IDEA.
 * Description: leetcode101 对称二叉树
 */
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
}

public class Test2 {
    public boolean isSymmetric(TreeNode root) {
        if(root == null) {
            return false;
        }
        return func(root.left, root.right);
    }

    private boolean func(TreeNode node1, TreeNode node2) {
        if(node1 != null && node2 != null) {
            if(node1.val == node2.val) {
                return func(node1.left, node2.right) && func(node1.right, node2.left);
            }else {
                return false;
            }
        }else if(node1 != null || node2 != null) {
            return false;
        }
        return true;
    }
}
